var express = require('express');
var router = express.Router();

var reqUtil = require('../lib/req');
var LINK = require('../api/link');


router.get('/school', function(req, res) {
    var k = req.query.k;
    var l = req.query.l;
    reqUtil.getData(LINK.REQ_GET_SCHOOL + k, function(code, data) {
        if (!code) {
            res.json({ code: 0, result: data });
        } else {
            res.json({ code: code, result: data });
        }
    });
});

router.get('/class/:id', function(req, res) {
    var id = req.params.id;
    reqUtil.getData(LINK.REQ_GET_CLASS + id, function(code, data) {
        if (!code) {
            res.json({ code: 0, result: data });
        } else {
            res.json({ code: code, result: data });
        }
    });
});

router.get('/sms/:id', function(req, res) {
    var id = req.params.id;
    console.log('code', id);
    //res.json({ code: 0, result: '123456' });
    reqUtil.postData(LINK.REQ_SMS_CODE, { sms_main: { phone: id } }, function(code, data) {
        console.log(code, data);
        if (!code) {
            res.json({ code: 0, result: data.sms_id });
        } else {
            res.json({ code: code, result: data });
        }
    });
});

module.exports = router;